package com.mm.cloud.lease.service.impl.convert.tenant;

import com.mm.cloud.lease.dto.tenant.form.SaveTenantDTO;
import com.mm.cloud.lease.dto.tenant.form.UpdateTenantDTO;
import com.mm.cloud.lease.entity.Tenant;

public class TenantConvert {

    public static Tenant convert(SaveTenantDTO dto) {
        // 显式字段复制：确保可控、可读，避免隐式映射带来遗漏/类型不匹配
        Tenant tenant = new Tenant();
        tenant.setHousingId(dto.getHousingId());
        tenant.setRoomId(dto.getRoomId());
        tenant.setTenantNature(dto.getTenantNature());
        tenant.setTenantName(dto.getTenantName());
        tenant.setTenantIdtype(dto.getTenantIdtype());
        tenant.setTenantIdcard(dto.getTenantIdcard());
        tenant.setTenantPhone(dto.getTenantPhone());
        tenant.setTenantSex(dto.getTenantSex());
        tenant.setLeaseStartTime(dto.getLeaseStartTime());
        tenant.setLeaseEndTime(dto.getLeaseEndTime());
        tenant.setLeaseYear(dto.getLeaseYear());
        tenant.setLeaseMonth(dto.getLeaseMonth());
        tenant.setLeaseDay(dto.getLeaseDay());
        tenant.setPaymentAdvanceDay(dto.getPaymentAdvanceDay());
        tenant.setLeasePrice(dto.getLeasePrice());
        tenant.setPaymentMethod(dto.getPaymentMethod());
        tenant.setDepositPrice(dto.getDepositPrice());
        tenant.setChannelId(dto.getChannelId());
        tenant.setTenantRemark(dto.getTenantRemark());
        return tenant;
    }

    public static Tenant convert(UpdateTenantDTO dto) {
        // 复用保存转换逻辑，并补充主键 id
        Tenant tenant = convert((SaveTenantDTO) dto);
        tenant.setId(dto.getId());
        return tenant;
    }
}


